package com.ruoyi.project.experiment.onlineexperiment.service.impl;

import java.util.List;

import com.ruoyi.project.experiment.experimentstudent.mapper.TbExperimentReportMapper;
import com.ruoyi.project.experiment.onlineexperiment.domain.TbExperiment;
import com.ruoyi.project.experiment.onlineexperiment.mapper.TbExperimentMapper;
import com.ruoyi.project.experiment.onlineexperiment.service.ITbExperimentService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 在线实验项目Service业务层处理
 * 
 * @author lvyongwei
 * @date 2020-09-17
 */
@Service("experiment")
public class TbExperimentServiceImpl implements ITbExperimentService
{
    @Autowired
    private TbExperimentMapper tbExperimentMapper;

    @Autowired
    private TbExperimentReportMapper tbExperimentReportMapper;

    /**
     * 查询在线实验项目
     * 
     * @param experimentId 在线实验项目ID
     * @return 在线实验项目
     */
    @Override
    public TbExperiment selectTbExperimentById(Long experimentId)
    {
        return tbExperimentMapper.selectTbExperimentById(experimentId);
    }

    /**
     * 查询在线实验项目列表
     * 
     * @param tbExperiment 在线实验项目
     * @return 在线实验项目
     */
    @Override
    public List<TbExperiment> selectTbExperimentList(TbExperiment tbExperiment)
    {
        return tbExperimentMapper.selectTbExperimentList(tbExperiment);
    }

    /**
     * 新增在线实验项目
     * 
     * @param tbExperiment 在线实验项目
     * @return 结果
     */
    @Override
    public int insertTbExperiment(TbExperiment tbExperiment)
    {
        return tbExperimentMapper.insertTbExperiment(tbExperiment);
    }

    /**
     * 修改在线实验项目
     * 
     * @param tbExperiment 在线实验项目
     * @return 结果
     */
    @Override
    public int updateTbExperiment(TbExperiment tbExperiment)
    {
        return tbExperimentMapper.updateTbExperiment(tbExperiment);
    }

    /**
     * 删除在线实验项目对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteTbExperimentByIds(String ids)
    {
        tbExperimentReportMapper.deleteReportByExperimentId(Convert.toStrArray(ids));
        return tbExperimentMapper.deleteTbExperimentByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除在线实验项目信息
     * 
     * @param experimentId 在线实验项目ID
     * @return 结果
     */
    @Override
    public int deleteTbExperimentById(Long experimentId)
    {
        return tbExperimentMapper.deleteTbExperimentById(experimentId);
    }

    /**
     * 修改实验开放状态
     * @param tbExperiment
     * @return
     */
    @Override
    public int changeStatus(TbExperiment tbExperiment) {
        return tbExperimentMapper.changeStatus(tbExperiment);
    }


    /**
     * 添加指派教师
     * @return
     */
    @Override
    public int addTeacher(Long experimentId, List<Long> userIds){
        return tbExperimentMapper.addTeacher(experimentId,userIds);
    }

    /**
     * 获取已经指派的教师
     * @param experimentId
     * @return
     */
    @Override
    public List<Long> getAsignTeacher(Long experimentId) {
        return tbExperimentMapper.getAsignTeacher(experimentId);
    }


    /**
     * 查询开放的在线实验项目
     * @return 在线实验项目
     */
    @Override
    public List<TbExperiment> selectTbExperimentListOpen(TbExperiment tbExperiment) {
        return tbExperimentMapper.selectTbExperimentListOpen(tbExperiment);
    }
}
